<template>
  <!--成果报告附件start -->
  <el-dialog
    v-dialogDrag
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="dialogVisible"
    class="dialogStyleMiddle"
    :before-close="cancel"
  >
    <el-form
      v-if="dialogVisible"
      ref="addForm"
      class="dialog-form"
      :model="formData"
      label-width="80px"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="成果报告" prop="outlineList">
            <FileUplode
              ref="fileUplode"
              :edit-file-list="achievementList"
              :status="status"
              @getFileList="getOutline"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <DialogFooter />
    </div>
  </el-dialog>
  <!--勘察附件end -->
</template>

<script>
// 页面接口
import { experimentUploadFile, getExperiment } from '@/api/projectManage/ProjectAllocation/testCommission/index'
// 上传文件
import FileUplode from '@/components/Upload/FileUplode'
// dialog-footer
import DialogFooter from '@/components/Common/Btns/DialogFooter/index'
export default {
  components: {
    FileUplode,
    DialogFooter
  },
  data() {
    return {
      status: '',
      /* 新增 start*/
      achievementList: [],
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      formData: { // 新增数据
        id: '', // 项目id
        achievementList: []
      },
      /* 新增 end*/
      readOnly: true,
      FileList: []// 附件
    }
  },
  methods: {
    /* 新增/编辑弹层 start*/
    // 新增/编辑
    handleAdd(title, id) {
      this.dialogTitle = title
      this.dialogVisible = true
      if (id) {
        this.formData.id = id
        this.getDetailById(id)
      }
    },
    // 查询物探报告的详情
    getDetailById(id) {
      getExperiment(id).then(res => {
        if (res) {
          this.formData = { ...res.data }
          this.achievementList = res.data.achievementList
        }
      })
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
    },
    // 提交按钮
    submitForm() {
      this.$refs['addForm'].validate(valid => {
        if (valid) {
          experimentUploadFile(this.formData)
          this.msgSuccess('保存成功')
          this.dialogVisible = false
        }
      })
    },
    /* 新增弹层 end*/
    /** ************ 文件上传start *******************/
    // 接受文件上传 组件 回传过来的文件id
    getOutline(fileList, deleteFileIds) {
      this.formData.achievementList = fileList
      // this.formData.outlineListDelete = deleteFileIds
    }
    /** ************ 文件上传end *******************/
  }

}
</script>

<style>

</style>
